package com.example.navigationdemo.part3

import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import android.view.View
import android.widget.Toast
import androidx.navigation.fragment.findNavController
import com.example.navigationdemo.R
import com.example.navigationdemo.base.BaseFragment
import kotlinx.android.synthetic.main.fragment_arg_2.*
import kotlinx.android.synthetic.main.fragment_arg_2.view.*

class Arg2Fragment : BaseFragment() {
    override fun initView(rootView: View) {
        var arg1 = arguments?.getString("arg1")
        rootView.tv_arg.append(arg1)
        rootView.tv_to_activity_with_arg.setOnClickListener {
            if (TextUtils.isEmpty(et_arg.text.toString())) {
                Toast.makeText(rootView.context, "参数不能为空", Toast.LENGTH_SHORT).show()
                return@setOnClickListener
            }
            var bundle = Bundle();
            bundle.putString("arg2", et_arg.text.toString())
            findNavController().navigate(R.id.to_activity, bundle)
        }
    }

    override fun getLayoutId(): Int {
        return R.layout.fragment_arg_2
    }
}